package com.lx.service;

import com.lx.bean.User;
import com.lx.bean.UserExample;
import com.lx.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    public List<User> selAll() {


        return userMapper.selectByExample(null);
    }
    public List<User> findUserInfo(String username) {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);

        return userMapper.selectByExample(example);
    }

    public int insertUser(User user) {
        int insert = userMapper.insert(user);
        System.out.println(insert + "qqqqqqqqqqqqqqq");
        return insert;
    }

    public User login(String username, String password) {
        System.out.println(username + " : " + password);
        List<User> users = userMapper.selectByExample(null);
        for (User user1 : users) {
            if ((user1.getUsername().equals(username) || user1.getNickname().equals(username)) && user1.getPassword().equals(password)) {
                return user1;
            }
        }
        return null;
    }

}
